<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--企业数据-->
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input v-model="deptName" placeholder="请输入名称" clearable size="small" prefix-icon="el-icon-search"
            style="margin-bottom: 20px" />
        </div>
        <div class="head-containers">
          <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
            :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
            @node-click="handleNodeClick" />
        </div>
      </el-col>
      <!--小区数据-->
      <el-col :span="20" :xs="24">
        <el-card class="box-card">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="用户名称" prop="customerName">
              <el-input v-model="queryParams.customerName" placeholder="请输入用户名称" clearable style="width: 150px" />
            </el-form-item>
            <el-form-item label="手机号码" prop="telephone">
              <el-input v-model="queryParams.telephone" placeholder="请输入用户手机号码" clearable style="width: 150px" />
            </el-form-item>
            <el-form-item label="表号" prop="meterCode">
              <el-input v-model="queryParams.meterCode" placeholder="请输表号" clearable style="width: 150px" />
            </el-form-item>

            <el-form-item label="指令类型" prop="instructType">
              <el-select v-model="queryParams.instructType" placeholder="请选择" clearable style="width: 150px">
                <el-option key="00" label="激活" value="00">激活</el-option>
                <el-option key="01" label="关阀" value="01">关阀</el-option>
                <el-option key="02" label="开阀" value="02">开阀</el-option>
                <el-option key="03" label="调价" value="03">调价</el-option>
                <el-option key="04" label="充值" value="04">充值</el-option>
                <el-option key="05" label="扣费" value="05">扣费</el-option>
                <el-option key="06" label="冲正" value="06">冲正</el-option>
                <el-option key="09" label="缴费补发" value="09">缴费补发</el-option>
                <el-option key="10" label="退费补发" value="10">退费补发</el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="操作结果" prop="status">
              <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 150px">
                <el-option key="0" label="已取消" value="0">已取消</el-option>
                <el-option key="1" label="待执行" value="1">待执行</el-option>
                <el-option key="2" label="已下发" value="2">已下发</el-option>
                <el-option key="3" label="成功" value="3">成功</el-option>
                <el-option key="4" label="作废" value="4">作废</el-option>
                <el-option key="5" label="失败" value="5">失败</el-option>
                <el-option key="6" label="已过期" value="6">已过期</el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-row :gutter="10" class="mb8" style="margin-top:20px">
            <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                         v-hasPermi="['system:instructLog:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="postList" border @selection-change="handleSelectionChange">
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column label="用户名称" align="center" prop="customerName" />
            <el-table-column label="商户号" align="center" prop="mchNo" />
            <el-table-column label="流水号" align="center" prop="flowNo" />
            <el-table-column label="表号" align="center" prop="meterCode" />
            <el-table-column label="发送时间" align="center" prop="sendTime" />
            <el-table-column label="操作结果" align="center" prop="status" width="120">
              <template slot-scope="scope">
                <span v-if="scope.row.status == 0">已取消</span>
                <span v-if="scope.row.status == 1">待执行</span>
                <span v-if="scope.row.status == 2">已下发</span>
                <span v-if="scope.row.status == 3">成功</span>
                <span v-if="scope.row.status == 4">作废</span>
                <span v-if="scope.row.status == 5">失败</span>
                <span v-if="scope.row.status == 6">已过期</span>

              </template>
            </el-table-column>
            <!-- <el-table-column label="操作内容" align="center" prop="instructContent" :show-overflow-tooltip="true" /> -->
            <el-table-column label="指令类型" align="center" prop="instructName" />
            <el-table-column label="描述" align="center" prop="remark" />
            <!--<el-table-column label="操作人" align="center" prop="operUser" />-->
          </el-table>

          <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-card>

      </el-col>
    </el-row>

  </div>
</template>
    
<script>

import { areaTreeList } from "@/api/fileManagement/areainfo.js"
import { openValue, closeValue, activationValue } from "@/api/service/online.js"
import { getHistory } from "@/api/service/online.js"

export default {
  name: "civilArchives",
  components: {},
  dicts: ["sys_normal_disable", "customer_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小区表格数据
      userList: null,
      // 弹出层标题
      title: "",
      //表计弹出层标题
      title2: "",
      // 企业树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 企业名称
      deptName: undefined,
      //是否表计显示弹出层
      bjOPen: false,
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: undefined,
        meterModel: undefined,
        supportNet: 1,
        isBlack: 'N'
      },
      activeNames: ["1"],
      postList: [],
    };
  },
  watch: {
    // 根据名称筛选企业树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
    this.getDeptTree();
  },
  methods: {
    /** 查询小区列表 */
    getList() {
      this.loading = true;
      let search = this.queryParams;
      search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
      search.params['meterCode'] = search.meterCode;
      getHistory(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询企业下拉树结构 */
    getDeptTree() {
      areaTreeList().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection)
      selection.map((item) => {
        this.ids.push(item.id)
      });
      this.single = selection.length != 1;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/instructLog/export",
        {
          ...this.queryParams,
        },
        `指令流水_${new Date().getTime()}.xlsx`
      );
    },


  },
};
</script>
<style lang="scss">
.head-containers {
  width: 200px;
  overflow: auto;

  .el-tree {
    min-width: 100%;
    display: inline-block !important;
  }
}
</style>
